#!/usr/bin/python
#
# Copyright 2015 HackyDH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os
#for android screen
#os.environ['KIVY_DPI'] = '320'
#os.environ['KIVY_METRICS_DENSITY'] = '2'
import kivy
kivy.require('1.8.0')

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.screenmanager import RiseInTransition
from kivy.uix.popup import Popup
from kivy.logger import Logger
from kivy.core.audio import SoundLoader
from kivy.lang import Builder

class LoginScreen(Screen):
    def login(self, instance):
        if self.ids.username.text != 'hacky' or \
                self.ids.password.text != '123':
            SoundLoader.load('error.wav').play()
            MyPopup().open()
            Logger.info('LoginScreen: username or pwd is wrong')
        else:
            SoundLoader.load('ok.wav').play()
            self.manager.current = 'circle'

class MyPopup(Popup):
    pass

class CircleScreen(Screen):
    pass

class MyApp(App):
    def build(self):
        self.icon = 'my.png'
        root = ScreenManager(transition=RiseInTransition())
        root.add_widget(LoginScreen())
        root.add_widget(CircleScreen())
        return root
    def build_config(self, config):
        config.setdefaults('myconfig', {
            'key1': 'value1',
            'key2': '42'})
    def build_settings(self,settings):
        jsondata = '''
            [
                {"type": "options",
                "title": "My first key",
                "desc": "Description of my first key",
                "section": "myconfig",
                "key": "key1",
                "options": ["value1", "value2", "another value"] },
                {"type": "title",
                "title": "Numeric" },
                { "type": "numeric",
                "title": "My second key",
                "desc": "Description of my second key",
                "section": "myconfig",
                "key": "key2" }
            ]'''
        settings.add_json_panel('Settings',self.config,data=jsondata)
if __name__ == '__main__':
    MyApp().run()